<!DOCTYPE html>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>highlight.cmake</title>
<meta name="generator" content="KF5::SyntaxHighlighting (CMake)"/>
</head><body style="color:#1f1c1b"><pre>
<span style="color:#898887;"># This CMakeLists.txt doesn't do anything useful,</span>
<span style="color:#898887;"># but it shoudl demonstrate the cmake syntax highlighting</span>
<span style="color:#898887;">#</span>
<span style="color:#898887;"># Alex Turbov &lt;i.zaufi@gmail.com&gt;</span>
<span style="color:#898887;">#</span>

<span style="color:#0057ae;background-color:#e0e9f8;">#[[.rst:</span>
<span style="color:#898887;">Demo</span>
<span style="color:#898887;">----</span>

<span style="color:#898887;">This is an</span><span style="font-weight:bold;"> **RST**</span><span style="color:#898887;"> documentation.</span>

<span style="color:#0057ae;">::</span>

<span style="color:#0057ae;">    # Sample code block</span>
<span style="color:#0057ae;">    blah-blah</span>

<span style="color:#898887;">But we are about to test CMake here ;-)</span>

<span style="color:#0057ae;background-color:#e0e9f8;">#]]</span>

<span style="font-weight:bold;">cmake_policy</span>(<span style="color:#006e28;">VERSION</span> 3.11)

<span style="font-weight:bold;">project</span>(
    Demo <span style="color:#006e28;">VERSION</span> 1.0
    <span style="color:#006e28;">DESCRIPTION</span> <span style="color:#bf0303;">&quot;For unit testing purposes&quot;</span>
    <span style="color:#898887;"># </span><span style="color:#81ca2d;background-color:#f7e6e6;font-weight:bold;">NOTE</span><span style="color:#898887;"> that particular languages is a separate style</span>
    <span style="color:#898887;"># to highlight &quot;special&quot; (well known values)</span>
    <span style="color:#006e28;">LANGUAGES</span> <span style="color:#006e28;">C</span> <span style="color:#006e28;">CXX</span>
  )

<span style="font-weight:bold;">set</span>(SOME_TRUE_OPTION <span style="color:#30a030;">TRUE</span>)      <span style="color:#898887;"># `true` value</span>
<span style="color:#898887;"># `false` value and &quot;internal&quot; variable</span>
<span style="font-weight:bold;">set</span>(<span style="color:#303030;">_ANOTHER_FALSE_OPTION</span> <span style="color:#e05050;">OFF</span> <span style="color:#006e28;">CACHE</span> <span style="color:#006e28;">INTERNAL</span> <span style="color:#bf0303;">&quot;Internal option&quot;</span>)

<span style="color:#898887;">#BEGIN Message block</span>
<span style="font-weight:bold;">message</span>(<span style="color:#006e28;">FATAL_ERROR</span> <span style="color:#bf0303;">&quot;Ordinal message do </span><span style="color:#b08000;">${VARIABLE_EXPANSION}</span><span style="color:#bf0303;">&quot;</span>)
<span style="font-weight:bold;">message</span>(<span style="color:#006e28;">AUTHOR_WARNING</span> <span style="color:#bf0303;">&quot;... standard variables have a dedicated style&quot;</span>)
<span style="font-weight:bold;">message</span>(<span style="color:#006e28;">SEND_ERROR</span> <span style="color:#bf0303;">&quot;e.g. </span><span style="color:#b08000;">${</span><span style="color:#c09050;">PROJECT_DESCRIPTION</span><span style="color:#b08000;">}</span><span style="color:#bf0303;"> or </span><span style="color:#b08000;">${</span><span style="color:#c09050;">CMAKE_COMMAND</span><span style="color:#b08000;">}</span><span style="color:#bf0303;">&quot;</span>)
<span style="font-weight:bold;">message</span>(
    <span style="color:#006e28;">STATUS</span> <span style="color:#bf0303;">[=[</span>
<span style="color:#bf0303;">        Raw messages do not do ${VARIABLES_EXPANSION} or \n</span>
<span style="color:#bf0303;">        escape symbols highlighting...</span>
<span style="color:#bf0303;">    ]=]</span>
)
<span style="color:#898887;">#END Message block</span>

<span style="color:#898887;"># </span><span style="color:#e85848;background-color:#451e1a;font-weight:bold;">ATTENTION</span><span style="color:#898887;"> Every command highlight only its own named keywords...</span>
<span style="color:#898887;"># Also, note aliased (most of the time imported) targets higlighted as well</span>
<span style="font-weight:bold;">add_library</span>(<span style="color:#b08000;">Foo::foo</span> <span style="color:#006e28;">IMPORTED</span> <span style="color:#006e28;">GLOBAL</span>)
<span style="font-weight:bold;">set</span>(KW_HL IMPORTED GLOBAL)      <span style="color:#898887;"># `IMPORTED` and `GLOBAL` are not highlighted here!</span>

<span style="color:#898887;"># Properties are separate (&quot;special value&quot;) style</span>
<span style="font-weight:bold;">set_target_properties</span>(<span style="color:#b08000;">Foo::foo</span> <span style="color:#006e28;">PROPERTIES</span> <span style="color:#006e28;">LOCATION</span> <span style="color:#bf0303;">&quot;</span><span style="color:#b08000;">${FOO_LIBRARY}</span><span style="color:#bf0303;">&quot;</span>)

<span style="color:#898887;"># Generator expressions</span>
<span style="font-weight:bold;">target_compile_definitions</span>(
    <span style="color:#898887;"># </span><span style="color:#81ca2d;background-color:#f7e6e6;font-weight:bold;">NOTE</span><span style="color:#898887;"> Ok w/ CMake &gt;= 3.11</span>
    <span style="color:#b08000;">Foo::foo</span>
    <span style="color:#b86050;">$&lt;$&lt;</span><span style="color:#b84040;font-weight:bold;">PLATFORM_ID</span><span style="color:#b86050;">:Windows&gt;:WINDOWS_FOO&gt;</span>
    <span style="color:#b86050;">$&lt;$&lt;</span><span style="color:#b84040;font-weight:bold;">PLATFORM_ID</span><span style="color:#b86050;">:Linux&gt;:</span>
<span style="color:#b86050;">        LINUX_FOO</span>
<span style="color:#b86050;">        $&lt;$&lt;</span><span style="color:#b84040;font-weight:bold;">BOOL</span><span style="color:#b86050;">:</span><span style="color:#b08000;">${</span><span style="color:#303030;">_has_foo</span><span style="color:#b08000;">}</span><span style="color:#b86050;">&gt;:SOME_FOO_PATH=</span><span style="color:#b08000;">${</span><span style="color:#c09050;">PROJECT_BINARY_DIR</span><span style="color:#b08000;">}</span><span style="color:#b86050;">/foo&gt;</span>
<span style="color:#b86050;">    &gt;</span>
  )

<span style="color:#0057ae;background-color:#e0e9f8;">#[=======================================================================[.rst:</span>
<span style="color:#0057ae;">.. cmake:command:: </span><span style="color:#898887;">my_fun</span>

<span style="font-style:italic;">*RST*</span><span style="color:#898887;"> documentation</span><span style="color:#0057ae;"> ``can``</span><span style="color:#898887;"> refer to </span><span style="font-weight:bold;">:cmake:command:</span><span style="color:#b08000;">`any_commands`</span><span style="color:#898887;"> or</span>
<span style="font-weight:bold;">:cmake:variable:</span><span style="color:#b08000;">`variables`</span><span style="color:#898887;">...</span>

<span style="color:#0057ae;">.. code-block:: cmake</span>
<span style="color:#0057ae;">   :caption: **Synopsys**</span>

<span style="color:#0057ae;">    my_fun([ANYTHING...])</span>

<span style="color:#0057ae;background-color:#e0e9f8;">#]=======================================================================]</span>
<span style="font-weight:bold;">function</span>(my_fun)
    <span style="color:#898887;"># </span><span style="color:#ca9219;background-color:#451e1a;font-weight:bold;">TODO</span><span style="color:#898887;"> Add implementation</span>
<span style="font-weight:bold;">endfunction</span>()

<span style="color:#644a9b;">my_fun</span>(
    <span style="color:#898887;"># Custom functions do not highlight &quot;standard&quot; named args ...</span>
    PUBLIC LOCATION PARENT_SCOPE
    <span style="color:#898887;"># only some well-known values ...</span>
    <span style="color:#e05050;">smth-NOTFOUND</span> <span style="color:#30a030;">ON</span>
    <span style="color:#898887;"># and standard variables</span>
    <span style="color:#c09050;">PROJECT_VERSION</span>
    <span style="color:#898887;"># or substitutions</span>
    <span style="color:#b08000;">$ENV{HOME}</span> OR <span style="color:#b08000;">${</span><span style="color:#303030;">_internal_var_is_grey</span><span style="color:#b08000;">}</span>
  )

<span style="color:#898887;"># I dont'recall exactly, but there was some bug with `if`...</span>
<span style="font-weight:bold;">if</span>((A <span style="color:#006e28;">AND</span> <span style="color:#bf0303;">&quot;</span><span style="color:#b08000;">${B}</span><span style="color:#bf0303;">&quot;</span>) <span style="color:#006e28;">OR</span> C <span style="color:#006e28;">OR</span> (var <span style="color:#006e28;">MATCHES</span> <span style="color:#bf0303;">&quot;regex&quot;</span>))
    <span style="color:#898887;"># Anyway... it is Ok nowadays ;-)</span>

<span style="font-weight:bold;">elseif</span>(<span style="color:#006e28;">POLICY</span> <span style="color:#006e28;">CMP066</span>)
    <span style="font-weight:bold;">add_executable</span>(<span style="color:#b08000;">${</span><span style="color:#c09050;">PROJECT_NAME</span><span style="color:#b08000;">}</span> <span style="color:#b08000;">${</span><span style="color:#c09050;">PROJECT_NAME</span><span style="color:#b08000;">}</span>.cc)
    <span style="font-weight:bold;">target_link_libraries</span>(
        <span style="color:#b08000;">${</span><span style="color:#c09050;">PROJECT_NAME</span><span style="color:#b08000;">}</span>
        <span style="color:#006e28;">PRIVATE</span>
            <span style="color:#b08000;">Qt5::Core</span>
            <span style="color:#b86050;">$&lt;$&lt;</span><span style="color:#b84040;font-weight:bold;">BOOL</span><span style="color:#b86050;">:</span><span style="color:#b08000;">${HAS_FOO}</span><span style="color:#b86050;">&gt;:</span><span style="color:#b08000;">Foo::foo</span><span style="color:#b86050;">&gt;</span>
      )

<span style="font-weight:bold;">endif</span>()

<span style="color:#898887;"># In each function call below, all 3 named parameter lines should apply the same highlighting.</span>
<span style="font-weight:bold;">add_custom_command</span>(
    <span style="color:#006e28;">COMMAND</span> true
    <span style="color:#006e28;">COMMAND</span> (true)
    <span style="color:#006e28;">COMMAND</span> true
)
<span style="font-weight:bold;">add_custom_target</span>(TargetName
    <span style="color:#006e28;">WORKING_DIRECTORY</span> somedir
    <span style="color:#006e28;">COMMAND</span> (true)
    <span style="color:#006e28;">BYPRODUCTS</span> somefile
)
<span style="font-weight:bold;">execute_process</span>(
    <span style="color:#006e28;">COMMAND</span> true
    <span style="color:#006e28;">COMMAND</span> (true)
    <span style="color:#006e28;">COMMAND</span> true
)
<span style="font-weight:bold;">add_test</span>(
    <span style="color:#006e28;">NAME</span> sometest
    <span style="color:#006e28;">COMMAND</span> (true)
    <span style="color:#006e28;">WORKING_DIRECTORY</span> somedir
)
</pre></body></html>
